package seqlist.leetcode;
// 环的入口
public class Num142 {
    public ListNode detectCycle(ListNode head) {
        ListNode fast = head,low = head;
        while (fast != null && fast.next != null) {
            fast = fast.next.next;
            low = low.next;
            // 此时fast和low相遇
            if (fast == low) {
                ListNode third = head;
                while (third != low) {
                    third = third.next;
                    low = low.next;
                }
                return low;
            }
        }
        return null;
    }
}
